﻿<!---
 
  Copyright (c) 2010, Cristian Costantini - cristian@millemultimedia.it
  
  NotifyManager is licensed under the terms of the Open Source GPL 3.0 license. 
	
	http://www.gnu.org/licenses/gpl.html
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
--->
<cfcomponent output="false" accessors="true">

	<cfproperty name="name" type="string" />
	<cfproperty name="template" type="string" />
	<cfproperty name="type" type="string" />
	
	<cffunction name="init" access="public" returntype="Notice">
		<cfargument name="service" type="Component" required="true" />
		<cfargument name="property" type="Struct" required="true" />
		
		<cfset variables.service = arguments.service />
		<cfset variables.property = arguments.property />
		
		<cfset variables.renderer = createObject( 'component', 'notifyManager.template.TemplateRenderer' ) />
		
		<cfreturn this/>
	</cffunction>
	
	<cffunction name="before" access="public" returntype="void" output="false">
		<cfargument name="message" type="notifyManager.metadata.Message" required="true" />
		
    	<cfset execute( arguments.message ) />
		
    </cffunction>
	
	<cffunction name="around" access="public" returntype="void" output="false">
    	<cfargument name="message" type="notifyManager.metadata.Message" required="true" />
    	
    	<cfset execute( arguments.message ) />
    	
    </cffunction>
	
	<cffunction name="after" access="public" returntype="void" output="false">
    	<cfargument name="message" type="notifyManager.metadata.Message" required="true" />
		
    	<cfset execute( arguments.message ) />
    	
    </cffunction>
	
	<cffunction name="execute" access="private" returntype="void" output="false">
		<cfargument name="message" type="notifyManager.metadata.Message" required="true" />
    	
		<cfset merge( arguments.message ) />
		
		<cfset variables.renderer.render( arguments.message, getTemplate() ) />
		
		<cfset variables.service.execute( arguments.message ) />
		
    </cffunction>
	
	<cffunction name="merge" access="private" returntype="void" output="false">
		<cfargument name="message" type="notifyManager.metadata.Message" required="true" />
    	<cfset var key = "" />
		
    	<cfloop collection="#variables.property#" item="key">
    		
    		<cfinvoke component="#arguments.message#" method="set#key#">
				<cfinvokeargument name="#key#" value="#variables.property[ key ]#" />
			</cfinvoke>
    		
    	</cfloop>
    	
    </cffunction>

</cfcomponent>